package com.frank.subject.infra.rpc;

import com.frank.auth.api.UserFeignService;
import com.frank.auth.entity.AuthUserDto;
import com.frank.common.entity.Result;
import com.frank.subject.infra.rpc.entity.UserInfo;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

/**
 * @author Frank Zou
 * @version v0.0.1
 * @date 2025/3/12
 * @description
 */
@Component
public class  UserRpc {

    @Resource
    private UserFeignService userFeignService;

    public UserInfo getUserInfo(String userName) {
        Result<AuthUserDto> result = userFeignService.getUserInfo(userName);
        UserInfo userInfo = new UserInfo();
        if (!result.getSuccess()) {
            return userInfo;
        }
        AuthUserDto data = result.getData();
        userInfo.setUsername(data.getUserName());
        userInfo.setNickname(data.getNickName());
        userInfo.setAvatar(data.getAvatar());
        return userInfo;
    }
}
